"use client"; /** * /w/:workspace/favorites — the caller's favorited pages (Phase 3 PR-030). * * List → GET /workspaces/:wid/pages?favorites=true ({ data: Page[] }, * ordered by the favorite's fractional position — currently a * stable (position, pageId) order; the reorder API is not built yet) * Unstar→ DELETE /pages/:id/favorite (the PageFavorite row * is deleted; the page's isFavorite flag is not the source of * truth — it's only a default) * * A page trashed AFTER being starred still lists here (its trashedAt is set — * we badge it so the link target makes sense). */ import { useParams } from "next/navigation"; import Link from "next/link"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { Bookmark, BookmarkX, Database as DatabaseIcon, FileText, Loader2 } from "lucide-react"; import { formatRelativeTime } from "@/lib/utils"; import { pageApi } from "@/lib/api"; import { useWorkspace } from "@/hooks/use-workspace"; import { Page } from "@/lib/types"; export default function FavoritesPage() { const params = useParams<{ workspace: string }>(); const slugOrId = params?.workspace ?? ""; const workspaceSlug = params?.workspace ?? "default"; const { data: workspace } = useWorkspace(slugOrId); const qc = useQueryClient(); const favorites = useQuery({ // `["favorites"]` is the prefix useToggleFavorite invalidates (the toolbar // star must refresh this list without a full reload). queryKey: ["workspaces", workspace?.id ?? slugOrId, "favorites"], queryFn: () => pageApi.list(workspace?.id ?? slugOrId, { favorites: true, limit: 200 }), enabled: !!workspace?.id, retry: false }); const unfavorite = useMutation({ mutationFn: (pageId: string) => pageApi.removeFavorite(pageId), onSuccess: (_data, pageId) => { qc.invalidateQueries({ queryKey: ["favorites"] }); qc.invalidateQueries({ queryKey: ["workspaces", workspace?.id, "favorites"] }); qc.invalidateQueries({ queryKey: ["pages", pageId] }); } }); const items = favorites.data ?? []; return (

Favorites

Pages you've starred. Star one from a page's toolbar or its context menu.

{favorites.isLoading && (

Loading favorites…

)} {favorites.isError && (

Couldn't load your favorites.

)} {!favorites.isLoading && !favorites.isError && items.length === 0 && (

No favorites yet. Open a page and click the star in its toolbar (or right-click a page in the sidebar → “Add to favorites”).

)}
); }